package com.fortune.service.impl;

import com.fortune.dao.PTUserInfoDao;
import com.fortune.dto.in.pUser.PChangePasswordDto;
import com.fortune.dto.in.pUser.PLoginDto;
import com.fortune.dto.in.pUser.PResetPasswordDto;
import com.fortune.entity.PUserInfo;
import com.fortune.service.PTUserInfoService;
import com.fortune.vo.pUser.LoginPUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PTUserInfoServiceImpl implements PTUserInfoService {
    @Autowired
    private PTUserInfoDao ptUserInfoDao;

    /**
     * 检查登陆信息填写是否正确
     * @param loginDto
     * @return
     */
    @Override
    public int loginCheck(PLoginDto loginDto) {
        PUserInfo pUserInfo = ptUserInfoDao.phoneCheck(loginDto);
        if (pUserInfo == null){
            return 3;
        }else if (pUserInfo.getStatus().equals("NO")){
            return 2;
        }else {
            if (pUserInfo.getPassword().equals(loginDto.getPassword())) {
                return 0;
            }
        }
        return 1;
    }

    /**
     * 员工信息
     * @param loginDto
     * @return
     */
    @Override
    public PUserInfo pUserInfo(PLoginDto loginDto) {
        return ptUserInfoDao.pUserInfo(loginDto);
    }

    /**
     * 登陆返回信息
     * @param loginDto
     * @return
     */
    @Override
    public LoginPUserInfo loginPUserInfo(PLoginDto loginDto) {
        return ptUserInfoDao.loginPUserInfo(loginDto);
    }

    /**
     * 重置密码
     * @param resetPasswordDto
     * @return
     */
    @Override
    public int resetPassword(PResetPasswordDto resetPasswordDto) {
        return ptUserInfoDao.resetPassword(resetPasswordDto);
    }

    /**
     * 修改密码
     * @param pUserInfo
     * @param changePasswordDto
     * @return
     */
    @Override
    public int updatePassword(PUserInfo pUserInfo, PChangePasswordDto changePasswordDto) {
        return ptUserInfoDao.updatePassword(pUserInfo,changePasswordDto);
    }

    @Override
    public int queryPhoneExist(String phone) {
        return ptUserInfoDao.queryPhoneExist(phone);
    }
}
